package com.socket;

import java.io.*;

public class SocketTools {
    /**
     * 功能 将输入流内容转换为字节数组
     * @param is 输入流
     * @return
     * @throws IOException
     */
    public static byte[] streamtoByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        int readlen=0;
        byte []buf=new byte[1024];
        while((readlen=is.read(buf))!=-1){
            byteArrayOutputStream.write(buf,0,readlen);
        }
        byte []array=byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        return  array;
    }
}
